(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:BasicsCtrl
     * @description
     * # BasicsCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('BasicsCtrl', BasicsCtrl);

    BasicsCtrl.$inject = ['$scope', 'dataService', 'helper', 'dhfprinterService', '$timeout', '$interval', '$rootScope', '$state', 'moment'];

    function BasicsCtrl($scope, dataService, helper, dhfprinterService, $timeout, $interval, $rootScope, $state, moment) {
        $scope.listAction = function() {
            $scope.tabType = "periodst";
            $scope.getlist(1);
        }

        $scope.getlist = function(t) {
            var query = { query: { "store_id": $rootScope.store_id } };
            if ($scope.tabType == "periodst") {
                query.query.type_id = 1;
            }
            if ($scope.tabType == "timeslotstl") {
                query.query.type_id = 2;
            }

            dataService.templateGet(query).then(function(re1) {
                $scope.templates = re1.templates;
            });
        }

        //下载添加系统模板
        $scope.addTemplate = function() {
            var query = { query: { "is_built_in": 1, type_id: $scope.item.status } };
            dataService.templateGet(query).then(function(re1) {
                if (re1.templates.length) {
                    $scope.addApi(re1.templates[0]);
                }
            });
        }

        //执行添加api
        $scope.addApi = function(das) {
            var data = { "template_id": das.template_id, "title": $scope.item.title, store_id: $rootScope.store_id }
            dataService.templateAdd(data).then(function(re1) {
                helper.myAlert('success', null, null, function() {
                    $state.go("basics.list");
                });
            });
        }

        $scope.delete = function(template_id) {

            helper.myConfirm("确认删除吗？", function() {
                var data = { "template_id": template_id };
                dataService.templateDelete(data).then(function(da) {
                    var ti = da.Msg ? da.Msg : "success";
                    helper.myAlert(ti, null, null, function() {
                        $scope.getlist();
                    });
                });
            })
        }

        $scope.addAction = function() {

        }


    }
})();